package com.example.week12_networkprogramming;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created by Administrator on 2022/5/23.
 */

public class DBUtils {
    private static String user="root";
    private static String password="root";

    private static Connection getConn(String dbName)
    {
        Connection conn=null;
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            String url="jdbc:mysql://192.168.0.104:3306/"+dbName;
            conn= DriverManager.getConnection(url,user,password);
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return conn;
    }

     public static ResultSet queryReader(String reader_num)
     {
         ResultSet rs=null;
         Connection conn=getConn("library");
         if(conn!=null)
         {
             try{
                 PreparedStatement ps;
                 Statement smt=conn.createStatement();
                 String sql="select * from readers where reader_number LIKE '%"+reader_num+"%";
                 rs=smt.executeQuery(sql);

             }catch (SQLException throwables)
             {
                 throwables.printStackTrace();
             }
         }
         return rs;
     }



}
